<!--cust管理-->
<template>
    <div>
        <div class="panel panel-default panel-search">
            <el-form :inline="true">

                <el-form-item label="字典类型" prop="dictType">
                    <el-input v-model="page.query.param.dictType" clearable></el-input>
                </el-form-item>
                <el-form-item label="字典名称" prop="dictName">
                    <el-input v-model="page.query.param.dictName" clearable></el-input>
                </el-form-item>

                <el-form-item>
                    <el-button v-keycode="'ENTER'" type="primary" @click="search">查询</el-button>
                    <el-button @click="cancel">取消</el-button>

                </el-form-item>
            </el-form>
        </div>
        <v-toolbar title="应用系统" type="alert">
            <el-button plain type="primary" @click="create">新增</el-button>
            <el-button plain @click="exportRecords"><span style="color: green">导出</span></el-button>

        </v-toolbar>


        <v-table ref='table' :dblclick='edit' :page='page' :table-minheight='450' @dataloaded='onDataloaded'>
            <el-table-column :sortable='true' label='字典标识' prop='dictId' width='100'>
                <template slot-scope='{row}'>
                    {{ row.dictId }}
                </template>
            </el-table-column>
            <el-table-column :sortable='true' label='字典名称' prop='dictName' width='160'>
                <template slot-scope='{row}'>
                    {{ row.dictName }}
                </template>
            </el-table-column>
            <el-table-column :sortable='true' label='字典类型' prop='dictType' width='280'>

                <template slot-scope="scope">
                    <a :title="scope.row.dictType"
                       class="link-name"
                       href="javascript:;"
                       @click="edit(scope.row)">{{ scope.row.dictType }}
                    </a>
                </template>
            </el-table-column>
            <el-table-column :sortable='true' label='状态' prop='status' width='120'>
                <template slot-scope='{row}'>
                    {{ row.status == 0 ? '正常' : '停用' }}
                </template>
            </el-table-column>
            <el-table-column :sortable='true' label='应用' prop='remark' width="120">
                <template slot-scope='{row}'>
                    {{ row.remark }}
                </template>
            </el-table-column>
            <el-table-column :sortable='true' label='说明' prop='remark'>
                <template slot-scope='{row}'>
                    {{ row.remark }}
                </template>
            </el-table-column>
            <el-table-column :fixed='"right"' label='操作' width='80'>
                <template slot-scope='scope'>
                    <el-button title='编辑' type='text' @click='edit(scope.row)'>
                        <i class='el-icon-edit'></i>
                    </el-button>
                    <el-button title='删除' type='text' @click='del(scope.row,scope.$index)'>
                        <span style='color: red'> <i class='el-icon-delete red'></i></span>
                    </el-button>
                </template>
            </el-table-column>
        </v-table>
        <v-dialog ref="formDiag" :width="'600px'" title="信息编辑">
            <form-panel @saved="onFormSaved"></form-panel>
            <div slot="footer">
                <el-button type="primary" @click="$refs.formDiag.dispatch('submit')">保存</el-button>
                <el-button type="default" @click="()=>{$refs.formDiag.hide()}">取消</el-button>
            </div>
        </v-dialog>
    </div>
</template>
<style lang="less" rel="stylesheet/less" scoped>

.status_green {
    color: red;
}
</style>

<script>

import FormPanel from './Form';

export default {
    components: {FormPanel},
    data() {
        return {
            formStatus: 1,
            orderDateRange: [],
            summaryMap: {},
            page: {
                query: {
                    orderBys: 'dictId|desc',
                    param: {
                        dictId: undefined,
                        isDeleted: false
                    }
                },
                getData: this.$api.metadata.SysDictType.query

            },
            tableActions: [
                {
                    name: '编辑',
                    handle: this.edit
                },
                {
                    name: '删除',
                    handle: this.del,
                    style: 'color:red'
                }
            ]
        };
    },
    computed: {},

    methods: {
        onDataloaded(rsp) {

        },
        /*
        导出
         */
        exportRecords() {
            let params = this.getSearchParams();
            console.log(params);
            this.$api.metadata.SysDictType.export(params);
        },
        getSearchParams() {
            this.page.query.dateRanges = {};
            this.page.query.pageSize = 100;
            this.page.query.limit = 100;
            return this.page.query;
        },
        create() {
            this.$refs.formDiag.show();
        },

        edit(row) {
            this.$refs.formDiag.show({appId: row.appId});
        },
        toggleStatus(row) {
            let status = row.status;
            let msg = '确定上架此活动吗？</br><span style="color:red">一旦上架，部分信息不允许修改!</span>';
            if (status === 1) {
                msg = '确定下架此活动吗？</br><span style="color:red">一旦下架，已派发的优惠券无法使用!</span>';
            }
            this.$confirm(msg, '确认', {
                type: 'warning',
                dangerouslyUseHTMLString: true
            }).then(() => {
                this.$api.metadata.SysDictType.save(row.id).then(rsp => {
                    this.search();
                    this.$message({
                        type: 'success',
                        message: '操作成功!'
                    });
                });
            });
        },
        del(row) {
            this.$confirm('确定删除此条记录吗?', '提示', {
                type: 'warning'
            }).then(() => {
                this.$api.metadata.SysDictType.deleteById(row.appId).then(rsp => {
                    this.search();
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                });
            });
        },
        onFormSaved() {
            this.$refs.formDiag.hide();
            this.$nextTick(this.search);
        },
        init(options = {}) {
            this.search();
        },
        search() {
            this.$refs.table.load();
        },
        cancel() {
            this.dateRange = [];
            this.page.query.param = {};
            this.search();
        }
    },
    created() {
    },
    mounted() {
        this.$on('init', this.init);
    }
};
</script>
